﻿/// <reference path="allowinput.js" />
/// <reference path="jquery.js" />
/// <reference path="arealistdata.js" />
/// <reference path="validated5.js" />
/// <reference path="../ueditor/ueditor.all.js" />

function viod() { }
function UI() { }
//增加Iframe遮罩层，主要应用于IE6下拉列表与浮动元素之间的bug

UI.Opacity=function(el,a)
{
    el.css({ "opacity": a/100,"filter": "alpha(opacity="+a+")" });
}
UI.Load=function(matter)
{
    if(!matter)
    {
        matter="正在加载数据";
    }
    var box=this.box=$('<div><img src="/css/loading.gif" />'+matter+'</div>');

    box.css({ "position": "absolute","background": "white","padding": "10px 20px","top": "50%","border-radius": "10px","display": "none","vertical-align": "middle","left": "50%","margin-left": "-100px","margin-top": "-35px","zIndex": 9999999 });
    box.find("img").css({ "margin-right": "20px","vertical-align": "middle","width": "50px" });
    $(document.body).append(box);

}
UI.Load.prototype={
    show: function()
    {
        this.box.show();
    },
    hide: function()
    {
        this.box.hide();
    }
}
UI.Mask=function(a,color)
{
    a=a||30;
    this.Wrap=$("body");
    this.Box=$("<div></div>");
    if(this.Wrap.children().length)
    {
        this.Box.insertBefore(document.body.firstChild);
    }
    else
    {
        this.Wrap.append(this.Box);
    }

    this.Box.css({ "position": "absolute","background": color||"gray","opacity": a/100,"display": "none","zIndex": 1,"filter": "alpha(opacity="+a+")","top": 0,"left": 0 });

    var _t=this;
    this.Box.mousemove(function(e)
    {
        e.stopPropagation();
    })
    this.Box.click(function(e)
    {
        e.stopPropagation();
    })
    this.Box.contextmenu(function(e)
    {
        e.preventDefault();
    });
    this.Box.bind("mousewheel",function(e)
    {
        e.stopPropagation();
    });
    this.Box.mousedown(function(e)
    {
        e.stopPropagation();
    });
    this.Wrap.resize(function()
    {
        _t.SetSize();
    });
    $(window).load(function()
    {
        _t.SetSize();
    });
    $(window).resize(function()
    {
        _t.SetSize();
    });
}
UI.Mask.prototype.SetSize=function()
{
    var offset=$(document.body).offset();
    this.Box.css({ "width": $(window).width(),"height": Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,$(window).height(),$(document).height(),$(document.body).height()),"left": -(offset.left),"top": -(offset.top) });
}
UI.Mask.prototype.onShowBefore=function()
{

}
UI.Mask.prototype.onShowAfter=function()
{

}
UI.Mask.prototype.Show=function(time)
{
    var _t=this;
    _t.onShowBefore();
    _t.SetSize();
    _t.Box.fadeIn(time||0,function()
    {
        _t.onShowAfter();
    });
}
UI.Mask.prototype.onCloseAfter=function()
{

}
UI.Mask.prototype.onCloseBefore=function()
{

}
UI.Mask.prototype.Close=function(time)
{
    var _t=this;
    _t.onCloseBefore();
    _t.Box.fadeOut(time||0,function()
    {
        _t.onCloseAfter();
    });
}
/******************************************Cookie******************************************/
var Cookie={};
Cookie.domain=location.host;
Cookie.Get=function(k)
{
    if(!navigator.cookieEnabled)
    {
        alert("浏览本站需要打开浏览器的Cookie支持！");
        return;
    }
    if(document.cookie)
    {
        return document.cookie.replace(/; /img,";").toObject(";")[k]||false;
    }
}

//k:cookie文件，v:对应的值,n:保存天数,m:域
Cookie.Set=function(k,v,n,m)
{
    v=""+v;
    var r=/^s?[\w\u4e00-\u9fa5\/\.]*$/img
    if(!k.match(r)||!v.match(r))
    {
        return false;
    }
    var d=new Date();
    if(n)
    {
        d.setTime(d.getTime()+n*24*3600*1000);
        n=";expires="+(window.ActiveXObject?d.toGMTString():d);
    }
    else
    {
        n="";
    }
    m=m||this.domain;
    document.cookie=k+"="+v+";path=/"+n+';domain='+m;
    return true;
}
//移除指定的cookie
Cookie.Remove=function(k)
{
    this.Set(k,"",-100);
}
//移除所有cookie
Cookie.RemoveAll=function()
{
    var c=document.cookie.split(";");
    var len=c.length
    for(var i=0;i<len;i++)
    {
        this.Remove(c[i].split("=")[0]);
    }
}
Cookie.UserToken=function() { return "usertoken="+Cookie.Get("usertoken"); }
//本地存储
var Storage={};
Storage.Set=function(k,v)
{
    this.remove(k);
    window.localStorage.setItem(k,v);
}
Storage.Get=function(k)
{
    return window.localStorage?window.localStorage.getItem(k):null;
}
Storage.setJson=function(k,v)
{
    switch(v.constructor)
    {
        case Array:
            this.Set(k,Array.toJson(v));
            break;
        case Object:
            this.Set(k,Object.toJson(v));
            break;
        default:
            this.Set(k,v);
    }
}
Storage.getJson=function(k)
{
    var json=this.Get(k);
    if(json)
    {
        return json.toJson();
    }
    return {};
}
Storage.remove=function(k)
{
    window.localStorage.removeItem(k);
}
/******************************************以下扩展String对象的功能******************************************/
//获取字符长度；
String.prototype.lenDou=function()
{
    return this.replace(/[^\u0000-\u00FF]/img,"aa").length;
}
String.prototype.SubStrDou=function(len)
{
    var l=this.lenDou();
    if(len>l)
    {
        len=l;
    }
    var str="";
    var count=0;
    var s="";
    for(var i=0;i<len;i++)
    {
        s=this.substr(i,1);
        if(s.match(/[^\u0000-\u00FF]/))
        {
            count=count+2;
        }
        else
        {
            count++;
        }
        str+=s;
        if(count>=len)
        {
            return str;
        }
    }
    return str;
}
String.prototype.trimleft=function()
{
    return this.replace(/^\s+/,"");
}
String.prototype.trimright=function()
{
    return this.replace(/\s+$/,"");
}
String.prototype.trim=function()
{
    return this.trimleft().trimright();
}
String.prototype.SubStr=function(len)
{
    var l=this.length;
    if(l<len)
    {
        return this;
    }

    var str=this.substring(0,len);
    var idxstr=this.substring(len);
    var count=0;
    var s="";
    for(var i=0;i<len;i++)
    {
        s=idxstr.substr(i,1);
        if(s.match(/[^\u0000-\u00FF]/))
        {
            count=count+2;
        }
        else
        {
            count++;
        }
        str+=s;
        if(count>=len)
        {
            return str;
        }
    }
    return str;
}

//解析到json数据格式
String.prototype.toJson=function()
{
    var tmp=this.replace(/\n|\r/g,"");
    try
    {
        return eval("("+tmp+")");
    }
    catch(e)
    {
        try
        {
            return eval(tmp);
        }
        catch(e)
        {
            var div=document.createElement("div");
            document.body.appendChild(div);
            div.innerHTML=this;
            return this;
        }
    }
}

//删除HTML标识
String.prototype.DelHtml=function()
{
    return this.replace(/<.+?>/img,"");
}
//把字符串解析成日期时间
String.prototype.ParseDate=function()
{
    try
    {
        var re=/\d+/img;
        var ds=this.match(re);
        ds[1]=ds[1]-1;
        return new Date(parseInt(ds[0]),parseInt(ds[1]),parseInt(ds[2]),parseInt(ds[3])||0,parseInt(ds[4])||0,parseInt(ds[5])||0);
    }
    catch(e)
    {
        return new Date();
    }
}
//获取实体字符
String.prototype.getEntity=function()
{
    var t="";
    var len=this.length;
    for(var i=0;i<len;i++)
    {
        t=t+"&#"+this.charCodeAt(i)+";";
    }
    return t;
}
//把指定的字符转换为实体字符，多个参数之间使用','逗号分隔
String.prototype.toEntity=function()
{
    var len=arguments.length;
    var t=this;
    for(var i=0;i<len;i++)
    {
        t=t.replace(new RegExp(arguments[i],"img"),arguments[i].getEntity())
    }
    return t;
}
//把字符串日期转换为中文日期格式
String.prototype.toDateCn=function()
{
    return this.ParseDate().toDateCn();
}
//把KeyValue对的字符串转换成对象
String.prototype.toObject=function(s)
{
    if(!this.replace(/\s/img,""))
    {
        return {};
    }
    var arr=this.split(s||"&");
    var len=arr.length;
    var obj={};
    for(var i=0;i<len;i++)
    {
        var tmp=arr[i].split("=");
        obj[decodeURIComponent(tmp[0])]=decodeURIComponent(tmp[1]);
    }
    return obj;
}
//解析Url地址
String.prototype.ParseUrl=function()
{
    var obj={
        protocol: null,
        hostname: null,
        port: null,
        path: null,
        parameters: null,
        query: {},
        fragment: null
    }

    //先解析以问号分隔
    var rg=/^(http[s]?:\/\/)?([^\/\:]+)?(:\d+)?(\/[^;\?#]*)?(\/?\;[^\?#]*)?(\/?\?[^#]*)?(#.*)?/
    var ret=this.match(rg);

    obj.protocol=ret[1]||"";
    obj.hostname=ret[2]||"";
    obj.port=(ret[3]||" ").substring(1);
    obj.path=ret[4]||" ";
    obj.parameters=(ret[5]||" ").substring(1);
    obj.query=(ret[6]||" ").substring(1).toObject();
    obj.fragment=(ret[7]||" ").substring(1);
    return obj;
}
String.prototype.round=function(num)
{
    var t=parseFloat(isNaN(this)?0:this).round(num);
    t=t+1/Math.pow(10,num+1)+"";
    return t.substring(0,t.indexOf(".")+num+1);
}
String.prototype.idcard=function(uppercase)
{
    return this+(this.length>17?"":(uppercase?"X":"x"));
}
String.prototype.padleft=function(total,char)
{
    var len=this.length;
    var t=this;

    len=total-len;
    var s="";
    for(var i=0;i<len;i++)
    {
        s+=char;
    }
    return s+t;
}
String.prototype.padright=function(total,char)
{
    var len=this.length;
    var t=this;

    len=total-len;
    var s="";
    for(var i=0;i<len;i++)
    {
        s+=char;
    }
    return t+s;
}
String.prototype.tomoney=function(def,capital)
{
    var str="";
    if(capital)
    {
        var upper="亿万仟佰拾兆万仟佰拾亿仟佰拾万仟佰拾元角分";
        var len=this.length;
        for(var i=len-1;i>-1;i--)
        {
            str+=this.substring(i,1)+upper.substring(i,1);
        }
    }
    else
    {
        var money=this.match(/^\d/)&&this.indexOf(".")==-1?this+".00":this;
        var split=money.split(".");
        if(split[0])
        {
            var re=/(\d{1,3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?$/;
            var arr=re.exec(split[0]);
            if(arr)
            {
                arr.splice(0,1);
                str=arr.toString();
            }
        }
        if(split[1])
        {
            var re=/^(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{1,3})?/;
            var arr=re.exec(split[1]);
            if(arr)
            {
                arr.splice(0,1);
                str+="."+arr.toString();
            }
        }
        str=str.replace(/,{2,}/g,",").replace(",.",".").replace(".,",".");
    }
    return str||def||"0.00";
}
String.prototype.getkeywords=function(wn,group)
{
    if(!wn||wn<2)
    {
        wn=2;
    }
    var matter=this.replace(/[^\u4e00-\u9fa5]/ig,"");
    var kwls=new Object();
    var tk="";
    var Len=matter.length;
    var re=null;
    var div=null;
    for(var i=0;i<Len;i++)
    {
        tk=matter.substr(i,wn);
        if(tk.length<wn||kwls[tk])
        {
            continue;
        }
        re=eval("/"+tk+"/img");
        kwls[tk]=matter.match(re).length;

        tk=matter.substr(i,wn+1);
        if(tk.length<wn+1||kwls[tk])
        {
            continue;
        }
        re=eval("/"+tk+"/img");
        kwls[tk]=matter.match(re).length;
    }
    var kl=[];
    for(var kwl in kwls)
    {
        kl.push(kwls[kwl]+kwl);
    }
    delete kwls;
    kl.sort(Sort);
    function Sort(a,b)
    {
        var re=/[^\d]/img;
        var x=parseInt(a.replace(re,""));
        var y=parseInt(b.replace(re,""));
        if(x>y)
        {
            return -1;
        }
        if(x==y)
        {
            return 0;
        }
        if(x<y)
        {
            return 1;
        }
    }
    kl=kl.splice(0,group);
    return kl.join().replace(/\d/g,"");
}
$("[autokeywords]").click(function()
{
    var params=Object.Clone({ group: 10 },$(this).attr("autokeywords").toJson());
    switch(params["box"])
    {
        case "ueditor":
            $("#"+params["wrap"]).val(UE.getEditor(params["id"]).getContentTxt().getkeywords(params["len"],params["group"]));
            break;
    }
});

//转换为时间
Date.Parse=function(obj)
{
    obj=obj||new Date(1000,0,1);
    switch(obj.constructor)
    {
        case String:
            obj=obj.ParseDate();
            break;
        case Number:
            obj=new Date(obj*1000);
            break;
        case Array:
            obj=obj.join().ParseDate();
            break;
        case Date:
            break;
        default:
            obj=new Date();
    }
    return obj;
}

//时间相减
Date.prototype.Subtract=function(dt,farmat)
{
    if(typeof dt=="string")
    {
        dt=dt.ParseDate();
    }
    var ret=parseInt((this-dt)/1000);
    var miao=Math.abs(parseInt(ret%60)); //计算秒
    var m=Math.abs(parseInt(ret/60%60)); //计算分钟
    var h=Math.abs(parseInt((ret/60/60)%24)); //计算小时
    var d=parseInt(ret/60/60/24); //计算天数
    farmat=farmat||"DD天HH小时mm分ss秒";
    if(h<10)
    {
        h="0"+h;
    }
    if(m<10)
    {
        m="0"+m;
    }
    if(miao<10)
    {
        miao="0"+miao;
    }
    return farmat.replace("DD",d).replace("HH",h).replace("mm",m).replace("ss",miao);
}
Date.prototype.GetAge=function()
{
    var dt=new Date();
    var age=dt.getFullYear()-this.getFullYear();
    if(dt.getMonth()<this.getMonth()||dt.getDate()<this.getDate())
    {
        age-1;
    }
    return age;
}
Date.prototype.AddHour=function(val)
{
    this.setHours(this.getHours()+val);
}
Date.prototype.AddDay=function(val)
{
    var tmp=this.setDate(this.getDate()+val);
    return new Date(tmp);
}
//获取上一月
Date.prototype.GetPreMonth=function()
{
    var dt=this.toString("yyyy-MM-dd").ParseDate();
    dt.setDate(1);
    dt.setMonth(dt.getMonth()-1);
    return dt;
}
//获取下一月
Date.prototype.GetNextMonth=function()
{
    var dt=this.toString("yyyy-MM-dd").ParseDate();
    dt.setDate(1);
    dt.setMonth(dt.getMonth()+1);
    return dt;
}
//format:yyyy*MM*dd HH*mm*ss*ms
Date.prototype.toString=function(ft)
{
    if(this.getFullYear()===1000)
    {
        return "";
    }
    ft=ft||"yyyy-MM-dd HH:mm:ss";
    var tmp={
        "yyyy": this.getFullYear(),
        "yy": this.getFullYear().toString().substring(2),
        "MM": this.getMonth()+1,
        "dd": this.getDate(),
        "HH": this.getHours(),
        "hh": this.getHours(),
        "mm": this.getMinutes(),
        "ss": this.getSeconds()
    }
    for(var key in tmp)
    {
        var val=tmp[key];
        if(val.toString()<10)
        {
            val="0"+val;
        }
        ft=ft.replace(key,val);
    }
    return ft;
}
Date.prototype.GetCnWeek=function()
{
    var week=['日','一','二','三','四','五','六'];
    return week[this.getDay()];
}
//获取每月1号的星期数
Date.prototype.GetFirstDayWeek=function()
{
    var dt=this.toString().ParseDate();
    dt.setHours(0,0,0,0);
    dt.setDate(1);
    return dt.getDay();
}
//获取上一月的天数
Date.prototype.GetPreMonthDay=function()
{
    var dt=this.toString().ParseDate();
    dt.setHours(0,0,0,0);
    dt.setDate(1);
    dt.setDate(dt.getDate()-1);
    return parseInt(dt.getDate());
}
//获取下一月的天数
Date.prototype.GetNextMonthDay=function()
{
    var dt=this.toString().ParseDate();
    dt.setHours(0,0,0,0);
    dt.setDate(1);
    dt.setMonth(dt.getMonth()+2);
    dt.setDate(dt.getDate-1);
    return parseInt(dt.getDate());
}
//获取每月中的最大天数
Date.prototype.GetMaxDay=function()
{
    var dt=this.toString().ParseDate();
    dt.setHours(0,0,0,0);
    dt.setDate(1);
    dt.setMonth(dt.getMonth()+1);
    dt.setDate(dt.getDate()-1);
    return parseInt(dt.getDate());
}
Date.prototype.toDateCn=function(format)
{
    var day=new Date();
    day.setHours(23,59,59,999);
    var rt=day-this;
    var m=parseInt(rt/1000/60); //计算分钟
    var h=parseInt(m/60); //计算小时
    var d=parseInt(h/24); //计算天数
    if(this.getFullYear()<day.getFullYear())
    {
        return format?this.toString("yy"+format+"MM"+format+"dd hh:mm"):this.toString("yy年MM月dd日 hh:mm");
    }
    if(d>=3)
    {
        return format?this.toString("MM"+format+"dd hh:mm"):this.toString("MM月dd日 hh:mm");
    }
    if(d==2)
    {
        return this.toString("前天 hh:mm");
    }
    if(d==1)
    {
        return this.toString("昨天 hh:mm");
    }
    if(h>0&&h<24)
    {
        return this.toString("今天 hh:mm");
    }
    return "1秒前"
}
Number.prototype.round=function(num)
{
    var pow=Math.pow(10,num);
    return Math.round(this*pow)/pow;
}
Number.toTime=function(num,format)
{
    num=parseInt(num);
    var sym=parseInt(num%60); //计算剩余秒
    var xyfz=parseInt(num/60%60);  //剩余分钟数
    var xyxh=parseInt(num/60/60%24); //计算剩余小时
    var xyt=parseInt(num/60/60/24); //计算天数
    return xyt+"天"+xyxh+"时"+xyfz+"分";
}
Number.prototype.floor=function(num)
{
    var pow=Math.pow(10,num);
    return Math.floor(this*pow)/pow;
}
Number.prototype.tomoney=function(def)
{
    return this.toString().tomoney(def);
}

//URL处理
var Url=self.location.search.replace(/^\?/,"").toObject();
Url.host=location.host;
Url.parse=function(k)
{
    return Url[k]||false;
}
Url.querystring=function(data,opts)
{
    var urlstring=[];
    opts=opts||{};
    opts["delete"]=opts["delete"]||{};
    switch(data.constructor)
    {
        case Object:
            for(var key in data)
            {
                if(opts["delete"][key]!=true&&data[key])
                {
                    urlstring.push(key+"="+encodeURIComponent(Url[key]));
                }
            }
            return urlstring.join("&");
    }
}
var Hash=decodeURIComponent(location.hash.replace(/#/img,""));
if(Hash)
{
    Hash="{"+Hash+"}";
    Hash=Hash.toJson();
}
//对象克隆,支持多个对象向一个对象克隆,最后一个对象是复制到的对象
Object.Clone=function(from,to,over)
{
    if(!to||to.constructor!=Object)
    {
        to={};
    }
    for(var o in from)
    {
        if(to[o]!=undefined&&!over)
        {
            continue;
        }
        if(typeof from[o]=="object"&&from[o].constructor==Object)
        {
            to[o]={};
            Object.Clone(from[o],to[o]);
        }
        else
        {
            to[o]=from[o];
        }
    }
    return to;
}
Object.Keys=function(obj,keys)
{
    var tmp={};
    var len=keys.length;
    for(var i=0;i<len;i++)
    {
        tmp[keys[i]]=obj[keys[i]]||"";
    }
    return tmp;
}
Object.inherit=function(self,parent)
{
    self["base"]=parent;
    this.Clone(parent,self,false);
}
Object.Query=function(obj,where)
{
    try
    {
        if(!obj)
        {
            return {};
        }
        if(!where)
        {
            return obj;
        }
        var ret={}
        switch(where.constructor)
        {
            case Array:
                var re=where[1];
                if(where[1].constructor!=RegExp)
                {
                    re=new RegExp("^"+where[1]+"$","img");
                }
                for(var o in obj)
                {
                    if(obj[o][where[0]].toString().match(re))
                    {
                        ret[o]=obj[o];
                    }
                }
                break;
            case Number:
            case String:
                for(o in obj)
                {
                    if(obj[o]==where)
                    {
                        ret[o]=obj[o];
                    }
                }
                break;
            case Object:
                for(var key in where)
                {
                    var re=where[key];
                    if(where[key].constructor!=RegExp)
                    {
                        re=new RegExp("^"+where[key]+"$","img");
                    }
                    for(var o in obj)
                    {
                        if(obj[o][key].toString().match(re))
                        {
                            ret[o]=obj[o];
                        }
                    }
                }
                break;
            default:
                ret=obj;
        }
        return ret;
    }
    catch(e)
    {
        alert("在对像查询中出现错误："+where+","+e.messaage);
    }
}
Object.toJson=function(obj,where)
{
    if(!obj)
    {
        return null;
    }
    if(obj.constructor==Array)
    {
        return Array.toJson(obj);
    }
    if(where)
    {
        obj=this.Query(obj,where);
    }
    var tmp="";
    var key=null;
    var value=null;
    for(key in obj)
    {
        value=obj[key]===undefined?"undefined":obj[key];

        key='"'+key.toString().toEntity('"')+'"';
        switch(value.constructor)
        {
            case String:
                value='"'+value.toEntity('"')+'"';
                break;
            case Array:
                value=Array.toJson(value);
                break;
            case Boolean:
                value=true?"true":"false";
                break;
            case Object:
                value=Object.toJson(value);
                break;
        }
        tmp+=key+":"+value+",";
    }
    if(tmp.length>1)
    {
        tmp=tmp.substring(0,tmp.length-1);
    }
    return "{"+tmp+"}";
}
Object.toQuotes=function(obj)
{
    if(!obj)
    {
        return false;
    }
    switch(obj.constructor)
    {
        case Array:
            return Array.toQuotes(obj);
    }
    var value=null;
    for(key in obj)
    {
        value=obj[key];
        switch(value.constructor)
        {
            case String:
                value=value.replace(/&#34;/img,"\"").replace(/&#39;/img,"\'");
                break;
            case Array:
                value=Array.toQuotes(value);
                break;
            case Object:
                value=Object.toQuotes(value);
                break;
        }
        obj[key]=value;
    }
    return obj;
}

Object.getValues=function(dict,keys,split)
{
    var str=[];
    keys=keys.constructor==String?keys.split(","):keys;
    for(var i in keys)
    {
        if(dict[keys[i]])
        {
            str.push(dict[keys[i]]);
        }
    }
    return str.join(split==undefined?",":split);
}
Object.toRequest=function(obj)
{
    var temp="",type;
    var val="";
    for(var key in obj)
    {
        val=obj[key];
        if(val==null||val==undefined)
        {
            continue;
        }
        switch(val.constructor)
        {
            case String:
                temp=temp+"&"+key+"="+encodeURIComponent(val);
                break;
            case Number:
            case Boolean:
                temp=temp+"&"+key+"="+val;
                break;
            case Date:
                temp=temp+"&"+key+"="+val.toString();
                break;
            case Array:
                temp=temp+"&"+key+"="+encodeURIComponent(val.toString());
                break;
        }
    }
    return temp.substring(1);
}

Object.Count=function(obj,filter)
{
    var count=0;
    if(filter)
    {
        obj=this.Query(obj,filter);
    }
    for(var key in obj)
    {
        count++;
    }
    return count;
}

//把对象中的属性名转换成数组的元素值
Object.toArray=function(obj)
{
    var arr=[];
    for(var o in obj)
    {
        arr.push(o);
    }
    return arr;
}
Object.innerHTML=function(data,datadict)
{
    var html=null;
    var id=null;
    for(var key in data)
    {
        html=datadict[key]||data[key];
        id=document.getElementById("key");
        if(id)
        {
            switch(id.toLowerCase())
            {
                case "input":
                    $(id).val(html.split(","))
                    break;
                case "select":
                    id.value=html;
                    break;
                default:
                    id.innerHTML=html;
                    break;
            }
        }
    }
}
Array.IsExist=function(arr,val)
{
    var len=arr.length;
    for(var i=0;i<len;i++)
    {
        if(arr[i]==val)
        {
            return i;
        }
    }
    return false;
}
//把数据中的元素值转换成对象的属性名，属性对应值为数组索引号
Array.toObject=function(arr)
{
    var t={};
    var len=arr.length;
    for(var i=0;i<len;i++)
    {
        t[arr[i]]=i+1;
    }
    return t;
}
Array.toQuotes=function(arr)
{
    var len=arr.length;
    for(var i=0;i<len;i++)
    {
        value=arr[i];
        if(!isNaN(value))
        {
            value=parseInt(value)||value;
        }
        switch(value.constructor)
        {
            case String:
                value=value.replace(/&#34;/img,"\"").replace(/&#39;/img,"\'");
                break;
            case Array:
                value=Array.toQuotes(value);
                break;
            case Object:
                value=Object.toQuotes(value);
                break;
        }
        arr[i]=value;
    }
    return arr;
}
Array.toJson=function(arr,where)
{
    var tmp="";
    var value=null;
    var len=arr.length;

    for(var i=0;i<len;i++)
    {
        value=arr[i];
        if(!isNaN(value))
        {
            value=parseInt(value)||value;
        }
        switch(value.constructor)
        {
            case Number:
                break;
            case String:
                value='"'+value.toEntity('"')+'"';
                break;
            case Array:
                value=Array.toJson(value);
                break;
            case Object:
                value=Object.toJson(value);
                break;
            default:
                value='"'+value.toString().toEntity('"')+'"';
                break;
        }
        tmp+=value+",";
    }
    if(tmp.length>1)
    {
        tmp=tmp.substring(0,tmp.length-1);
    }
    return "["+tmp+"]";
}
function getserverdt(event)
{
    $.get("/data/serverdt.aspx",function(data)
    {
        event(parseInt(data));
    });
}
var AreaDataHelper=function(province,city,county)
{
    if(!AreaListData)
    {
        return;
    }
    var province=this.province=$("#"+province)
    var city=this.city=$("#"+city)
    var county=this.county=$("#"+county)
    var data={};
    var html="";
    if(province.length)
    {
        createprovince();
    }

    function createprovince()
    {
        var def=province.attr("def");
        html="";
        data=Object.Query(AreaListData,[1,0]);
        var option=province.attr("option");
        if(option)
        {
            option=option.split("|");
            html+='<option value="'+option[0]+'">'+option[1]+'</option>';
        }
        for(var key in data)
        {
            html+='<option value="'+key+'" '+(key==def?"selected='selected'":"")+'>'+data[key][0]+'</option>';
        }
        province.html(html);
        createcity();
    }
    if(city.length)
    {
        province.change(function()
        {
            createcity();
        });
    }
    function createcity()
    {
        city.hide();
        county.hide();
        html="";
        data=null;
        if(province.val())
        {
            var def=city.attr("def");
            data=Object.Query(AreaListData,[1,province.val()]);
            var option=city.attr("option");
            if(option)
            {
                option=option.split("|");
                html+='<option value="'+option[0]+'">'+option[1]+'</option>';
            }
            for(var key in data)
            {
                html+='<option value="'+key+'" '+(key==def?"selected='selected'":"")+'>'+data[key][0]+'</option>';
            }
        }
        if(html)
        {
            city.show();
        }
        city.html(html);
        createcounty();
    }
    if(county.length)
    {
        city.change(function()
        {
            createcounty();
        });
    }
    function createcounty()
    {
        html="";
        data=null;
        if(city.val())
        {
            var def=county.attr("def");
            data=Object.Query(AreaListData,[1,city.val()]);
            var option=county.attr("option");
            if(option)
            {
                option=option.split("|");
                html+='<option value="'+option[0]+'">'+option[1]+'</option>';
            }
            for(var key in data)
            {
                html+='<option value="'+key+'" '+(key==def?"selected='selected'":"")+'>'+data[key][0]+'</option>';
            }
        }
        if(html)
        {
            county.show();
        }
        county.html(html);
    }
}
//
function BrowserEngine()
{
    var vendorPrefixes=['Moz','Webkit','Khtml','O','ms'],
			len=vendorPrefixes.length,
			vendor='';

    while(len--)
    {
        if((vendorPrefixes[len]+'Transform') in document.body.style)
        {
            vendor='-'+vendorPrefixes[len].toLowerCase()+'-';
            return vendor;
        }
    }
    return "";
}
//移动运营提供
function telphoneProvider(telphone)
{
    if(!telphone)
    {
        return false;
    } else if(telphone.match(/^1(34|35|36|37|38|39|50|51|52|57|58|59|82|83|87|88|47)/))
    {
        return "YD";
    } else if(telphone.match(/^1(30|31|32|56|85|86|45|55)/))
    {
        return "LT";
    } else if(telphone.match(/^1(33|53|80|81|89)/))
    {
        return "DX";
    }
    return false;
}
function scrollBarTop(top,el)
{
    if(!el)
    {
        el="html,body";
    }
    $(el).animate({ "scrollTop": top },500);
}
//模态对话框
function ModalDialog(params)
{
    params=params||{};
    params["var"]=params["var"]||window;
    params["url"]=params["url"]+"#"+Math.random().round(5);
    params["height"]=params["height"]||300;
    params["width"]=params["width"]||300;
    var ret=window.showModalDialog(params["url"],params["var"],"dialogHeight="+params["height"]+"px;dialogWidth="+params["width"]+"px;center=yes;resizable=yes;scroll=yes;status=0");
    ModalDialog.ReturnEvent(params["marker"],ret);
    return ret;
}
ModalDialog.onClick=function(target) { }
ModalDialog.ReturnEvent=function(marker,ret)
{
}

//jquery扩展
jQuery.fn.extend({
    "lazyload": function(scroller)
    {
        var screr=jQuery(scroller||window);
        screr.scroll(function()
        {
            lazyload();
        });
        jQuery(document).ready(function()
        {
            lazyload();
        });
        var that=this;
        var height=screr.height()+(scroller?screr.offset().top:0);
        function lazyload()
        {
            var viewbottom=screr.scrollTop()+height;
            var queue=jQuery(that).find("img[lazyload]");
            queue.each(function()
            {
                var offsetTop=jQuery(this).offset().top;
                if(offsetTop>=screr.scrollTop()&&offsetTop<viewbottom)
                {
                    var _t=jQuery(this);
                    var img=new Image();
                    img.onload=function()
                    {
                        _t.attr("src",img.src);
                        img=null;
                    }
                    img.src=_t.attr("lazyload");
                    _t.removeAttr("lazyload");
                }
            });
            queue=null;
        }
    },
    "horizontalslip": function()
    {
        $(this).each(function()
        {
            var t=$(this);  //
            var params=t.attr("horizontalslip").split(",");
            var action=t.find(params[0]);
            var target=$("#"+params[1]);
            var style=params[2];
            var width=parseInt(params[3]);
            var time=parseInt(params[4]||1000);
            target.width(action.length*width);
            target.show();
            action.mouseover(function()
            {
                action.removeClass(style);
                $(this).addClass(style);
                target.stop();
                var marginleft=0-(($(this).index()-0)*width);
                target.animate({ marginLeft: marginleft },time);
            });
        });
    },
    "verticalslip": function()
    {
        $(this).each(function()
        {
            var t=$(this);  //
            var params=t.attr("verticalslip").split(",");
            var action=t.find(params[0]);
            var target=$("#"+params[1]);
            var style=params[2];
            var height=parseInt(params[3]);
            var time=parseInt(params[4]||1000);
            action.mouseover(function()
            {
                action.removeClass(style);
                $(this).addClass(style);
                target.stop();
                var margintop=0-(($(this).index()-0)*height);
                target.animate({ marginTop: margintop },time);
            });
        });
    },
    "switchslip": function()
    {
        $(this).each(function()
        {
            var t=$(this);
            var params=t.attr("switchslip").split(",");
            var action=t.find(params[0]);
            var target=$("#"+params[1]).find(">*");
            var style=params[2];
            var height=parseInt(params[3]);
            var time=parseInt(params[4]||1000);
            var curel=target.first();
            action.mouseover(function()
            {
                var _t=$(this);
                action.removeClass(style);
                _t.addClass(style);
                target.fadeOut(time);
                curel=target.eq(_t.index());
                curel.stop();
                curel.fadeIn(time);
            });
        });
    },
    "slideslip": function()
    {
        $(this).each(function()
        {
            var t=$(this);
            var params=t.attr("slideslip").split(",");
            var action=t.find(params[0]);
            var target=$("#"+params[1]).find(">*");
            target.hide();
            var style=params[2];
            action.mouseover(function()
            {
                var _t=$(this);
                action.removeClass(style);
                _t.addClass(style);
                target.hide();
                target.eq(_t.index()).show();
            });
            action.first().mouseover();
        });
    },
    "menuslip": function()
    {
        $(this).each(function()
        {
            var t=$(this);
            var params=t.attr("menuslip").split(",");
            var action=t.find(params[0]);
            var style=params[1];
            action.mouseover(function(e)
            {
                e.stopPropagation();
                action.removeClass(style);
                $(this).addClass(style);
            });
            action.click(function(e)
            {
                e.stopPropagation();
                action.removeClass(style);
                var t=$(this);
                t.addClass(style);
                action.removeAttr("current");
                t.attr("current","current");
            });
            action.mouseout(function(e)
            {
                e.stopPropagation();
                var t=$(this);
                if(!t.attr("current"))
                {
                    t.removeClass(style);
                    action.filter("[current]").addClass(style);
                }
            });
            action.eq(parseInt(params[2])).click();
        });
    },
    "scrolltoel": function()  //滚动到元素
    {
        $(this).click(function()
        {
            var scrolltoel=$(this).attr("scrolltoel").split(",");
            scrollBarTop($("#"+scrolltoel[0]).offset().top+parseInt(scrolltoel[1]||0))
        });
    },
    "backtotop": function() //滚动到顶部
    {
        $(this).click(function()
        {
            scrollBarTop(0);
        });
    }
});
$("[horizontalslip]").horizontalslip();
$("[verticalslip]").verticalslip();
$("[backtotop]").backtotop();
$("[scrolltoel]").scrolltoel();
$("[switchslip]").switchslip();//slideslip
$("[slideslip]").slideslip();
$("[menuslip]").menuslip();

$("[riqidata]").each(function()
{
    var t=$(this);
    var data=t.attr("riqidata").split(",");
    if(!data[0])
    {
        return;
    }
    var ft=data[1]||"yyyy-MM-dd HH:mm:ss";
    switch(this.tagName.toLowerCase())
    {
        case "input":
            t.val(new Date(parseInt(eval(data[0]))*1000).toString(ft));
            break;
        default:
            t.html(new Date(parseInt(eval(data[0]))*1000).toString(ft));
            break;
    }
});
$("[fixedphone]").each(function()
{
    var t=$(this);
    var fixedphone=t.attr("fixedphone");
    if(fixedphone.length<8)
    {
        return;
    }
    var quhao=/^(10|2[\d]|[\d]{3})/g;
    var phone=fixedphone.match(quhao);
    switch(this.tagName.toLowerCase())
    {
        case "input":
            break;
        default:
            t.html(fixedphone.replace(quhao,function(val)
            {
                return "0"+val+"-";
            }));
            break;
    }
});
$("[allselect]").click(function()
{
    var item=$("[name='"+$(this).attr("allselect")+"']");
    item.each(function()
    {
        this.checked=!this.checked;
    });
});
$("[empty]").each(function()
{
    var t=$(this);
    var tmp=t.attr("empty").split("|");
    t.html(tmp[0]||tmp[1]||"");
});
$("[money]").each(function()
{
    var t=$(this);
    var money=t.attr("money").split(",");
    t.html(money[0].tomoney(money[1]));
});
$("[areadata]").each(function()
{
    var t=$(this);
    if(this.tagName.toLowerCase()=="select")
    {
        var def=t.attr("areadata");
        t.find("option").each(function()
        {
            if(this.value==def)
            {
                this.selected=true;
                t.change();
            }
        });
    }
    else
    {
        var data=t.attr("areadata").split("|");
        var area=data[0].split(",");
        var len=area.length;
        var html=[];
        for(var i=0;i<len;i++)
        {
            html.push(AreaListData[area[i]]?AreaListData[area[i]][0]:(area[i]==0?"":area[i]));
        }
        t.html(html.join(data[1]||""));
    }
});
$("[idcard]").each(function()
{
    var t=$(this);
    var idcard=t.attr("idcard");
    if(idcard.length==17)
    {
        idcard+="X"
    }
    switch(this.tagName.toLowerCase())
    {
        case "input":
            t.val(idcard);
            break;
        default:
            t.html(idcard);
            break;
    }
});
//时
$("[hourselect]").each(function()
{
    var t=$(this);
    var html="";
    for(var i=0;i<24;i++)
    {
        html+='<option value="'+i+'">'+i+'</option>';
    }
    t.html(html);
    t.val(t.attr("hourselect"));
});
//分
$("[minuteselect]").each(function()
{
    var t=$(this);
    var html="";
    for(var i=0;i<60;i++)
    {
        html+='<option value="'+i+'">'+i+'</option>';
    }
    t.html(html);
    t.val(t.attr("minuteselect"));
});
//秒
$("[secondselect]").each(function()
{
    var t=$(this);
    var html="";
    for(var i=0;i<60;i++)
    {
        html+='<option value="'+i+'">'+i+'</option>';
    }
    t.html(html);
    t.val(t.attr("secondselect"));
});

//点击表行自动选中
$("[trclickselect]").each(function()
{
    var tmp=$(this);
    $(this).find("tr").click(function()
    {
        var t=$(this);
        t.find(tmp.attr("trclickselect")).prop("checked",true);
    });
});



$(window).ready(function()
{
    if(window.dictdata)
    {
        var html="";
        var data={};
        $("[radiowrap]").each(function()
        {
            var t=$(this);
            var datakey=t.attr("datakey")||t.attr("radiowrap");
            var html="";
            data={};
            var datadict=t.attr("datadict")?dictdata[t.attr("datadict")]:dictdata;
            var disabled=Array.toObject((t.attr("datadisabled")+"").split(","));
            if(t.attr("keysvalue"))
            {
                datadict=Object.Clone(t.attr("keysvalue").toJson(),datadict,true);
            }
            if(t.attr("keys"))
            {
                var keys=t.attr("keys").split(",")
                var len=keys.length;
                for(var i=0;i<len;i++)
                {
                    if(datadict[datakey][keys[i]])
                        data[keys[i]]=datadict[datakey][keys[i]];
                }
            }
            else
            {
                data=datadict[datakey];
            }
            for(var key in data)
            {
                html+='<input type="radio" name="'+(t.attr("asname")||datakey)+'"'+(disabled[key]?' disabled="disabled"':"")+' id="'+datakey+key+'" value="'+key+'" /><label for="'+datakey+key+'">'+(data[key].constructor==Array?data[key][0]:data[key])+'</label>';
            }
            $(this).html(html);
            t.find("input").val([t.attr("def")]);
        });

        $("[checkboxwrap]").each(function()
        {
            var t=$(this);
            var id=t.attr("datakey")||t.attr("checkboxwrap");
            var html="";
            data={};
            var datadict=t.attr("datadict")?dictdata[t.attr("datadict")]:dictdata;
            var disabled=Array.toObject((t.attr("datadisabled")+"").split(","));
            if(t.attr("keysvalue"))
            {
                datadict=Object.Clone(t.attr("keysvalue").toJson(),datadict,true);
            }
            if(t.attr("keys"))
            {
                var keys=t.attr("keys").split(",")
                var len=keys.length;
                for(var i=0;i<len;i++)
                {
                    if(datadict[id][keys[i]])
                        data[keys[i]]=datadict[id][keys[i]];
                }
            }
            else
            {
                data=datadict[id];
            }
            for(var key in data)
            {
                html+='<label for="'+id+key+'"><input type="checkbox" name="'+(t.attr("asname")||id)+'"'+(disabled[key]?' disabled="disabled"':"")+' id="'+id+key+'" value="'+key+'" />'+(data[key].constructor==Array?data[key][0]:data[key])+'</label>';
            }
            $(this).html(html);
            var def=t.attr("def");
            if(def)
            {
                t.find("input").val(def.split(","));
            }
        });

        function datakeydefault(datadict,datakey,dict)
        {
            var el=dict?$("[datadict="+dict+"][datakey="+datakey+"]"):$("["+datakey+"]");
            el.each(function()
            {
                var t=$(this);
                if(t.attr("radiowrap")||t.attr("checkboxwrap")||t.attr("menuradiowrap"))
                {
                    return;
                }
                dict=datadict[datakey];
                if(t.attr("keysvalue"))
                {
                    dict=Object.Clone(t.attr("keysvalue").toJson(),dict,true);
                }
                if(t.attr("keys"))
                {
                    var data={};
                    var keys=t.attr("keys").split(",")
                    var len=keys.length;
                    for(var i=0;i<len;i++)
                    {
                        if(dict[keys[i]])
                            data[keys[i]]=dict[keys[i]];
                    }
                    dict=data;
                }
                var attr=t.attr(datakey);
                switch(this.tagName.toLowerCase())
                {
                    case "input":
                        t.val(dict[attr]);
                        break;
                    case "select":
                        var html="";
                        var option=t.attr("option");
                        if(option)
                        {
                            option=option.split("|");
                            html+='<option value="'+option[0]+'">'+option[1]+'</option>';
                        }
                        for(var option in dict)
                        {
                            html+='<option value="'+option+'">'+(dict[option].constructor==Array?dict[option][0]:dict[option])+'</option>';
                        }
                        t.html(html);
                        if(attr)
                        {
                            t.find("option").each(function()
                            {
                                if(this.value==attr)
                                {
                                    this.selected=true;
                                    t.change();
                                }
                            });
                        }
                        break;
                    default:
                        var keys=attr.split(",");
                        var len=keys.length;
                        var def=[];
                        var data="";
                        for(var i=0;i<len;i++)
                        {
                            data=dict[keys[i]];
                            if(data!==undefined)
                            {
                                def.push(data.constructor==Array?data[0]:data);
                            }
                        }
                        t.html(def.length>0?def.join(","):attr);
                        break;
                }
            });
        }
        $.each(dictdata,function(key)
        {
            datakeydefault(dictdata,key);
        });
        $("[datadict]").each(function()
        {
            var t=$(this);
            var datadict=dictdata[t.attr("datadict")]||window.dictdata;
            var datakey=t.attr("datakey");
            if(datadict&&datadict[datakey])
                datakeydefault(datadict,datakey,t.attr("datadict"));
        });
        $("select[def]").each(function()
        {
            var t=$(this);

            var def=this.getAttribute("def");
            t.find("option").each(function()
            {
                if(this.value==def)
                {
                    this.selected=true;
                    t.change();
                }
            });
        });
    }
});
//AJAX助手
var ajaxhelper={}
ajaxhelper.config=function(marker,url,post,json)
{
    return ajaxhelper[marker]={
        "header": $("#"+marker+"menu"),
        "wrap": $("#"+marker+"list"),
        "marker": marker,
        "loading": $("[loading='"+marker+"']"),
        "topdelta": 0,
        "url": url,
        "params": function(marker) { return {}; },
        "post": post,
        "json": json||true,
        "curpage": 0,
        "totalpage": 0,
        "pagesize": 10,
        "scrollbar": true,
        "target": null,
        "onsucces": function(json) { },
        "onerror": function(json) { },
        "onclick": function(marker) { }
    };
}
ajaxhelper.ajax=function(url,params,post)
{
    $.ajax({
        type: post?"post":"get",
        url: url,
        data: params,
        error: function(jqXHR,textStatus,errorThrown)
        {
            ajaxhelper.onerror(errorThrown,textStatus,jqXHR);
        },
        success: function(data,textStatus,jqXHR)
        {
            data=data.toJson();
            ajaxhelper.onsucces(data,textStatus,jqXHR);
        }
    });
}
ajaxhelper.get=function(url,params)
{
    this.ajax(url,params,false);
}
ajaxhelper.post=function(url,params)
{
    this.ajax(url,params,true);
}
ajaxhelper.context=function(marker)
{
    return this[marker];
}
ajaxhelper.onerror=function(errorThrown,textStatus,jqXHR)
{

}
ajaxhelper.onsucces=function(data,textStatus,jqXHR)
{

}
ajaxhelper.initialize=function()
{
    $("[ajaxhelper]").each(function()
    {
        var t=$(this);
        var marker=t.attr("ajaxhelper");
        var config=ajaxhelper[marker]||{};
        config["target"]=t;
        if(t.attr("ajaxconfig"))
        {
            ajaxhelper[marker]=config=Object.Clone(config,t.attr("ajaxconfig").toJson());
        }
        t.click(function()
        {
            config.onclick(marker);
            config.curpage++;

            var loading=config["loading"];
            loading.show();
            $.ajax({
                type: config["post"]?"post":"get",
                url: config["url"],
                data: Object.Clone(config.params(marker),{ curpage: config.curpage,totalpage: config.totalpage,pagesize: config.pagesize }),
                error: function(jqXHR,textStatus,errorThrown)
                {
                    config.onerror(errorThrown,textStatus,jqXHR);
                    loading.hide();
                },
                success: function(data,textStatus,jqXHR)
                {
                    if(config["json"])
                    {
                        data=data.toJson();
                        config["totalpage"]=parseInt(data["totalpage"]);
                        if(config["scrollbar"]&&config["curpage"]>1)
                        {
                            scrollBarTop(config.wrap.offset().top+config.wrap.height()-config.topdelta);
                        }
                        if(config["totalpage"])
                        {
                            t.text("下一页("+config["curpage"]+"/"+config["totalpage"]+")");
                        }
                        config["curpage"]<config["totalpage"]?t.show():t.hide();
                        config.onsucces(data,textStatus,jqXHR);
                    }
                    else
                    {
                        config.onsucces(data,textStatus,jqXHR);
                    }
                    loading.hide();
                }
            });
        });
        if(config["auto"])
        {
            t.click();
        }
    });
};

$("[required]").each(function()
{
    $(this).append("<span class='red'>*</span>");
});
$("[ueditor]").each(function()
{
    var option="{"+$(this).attr("ueditor")+"}";
    UE.getEditor(this.id,option.toJson());
});
$("[iframeload]").each(function()
{
    this.src=$(this).attr("iframeload");
});